package juc.day01;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author wang hao
 * @date 2023-02-26 22:28
 */
public class Demo05 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println(getUserList());
    }


    static List<String> getUserList() throws InterruptedException {
        ArrayList<String> uidList = new ArrayList<>();
        ExecutorService es = new ThreadPoolExecutor(
                1,
                1,
                0L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingDeque<>(),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread thread = new Thread(r);
                        System.out.println("11111");
                        return thread;
                    }
                });

        es.submit(() -> {
            System.out.println("hello");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            uidList.add("1");
            System.out.println("exit");
        });

//        es.shutdown();
        // 会打断正在执行中的任务
        es.shutdownNow();
        // 主线程会处于一种等待的状态，等待线程池中所有的线程都运行完毕后才继续运行。
        es.awaitTermination(1,TimeUnit.MINUTES);
        return uidList;
    }



}
